public class Solution2 {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        if(headA==null||headB==null)
            return null;
        ListNode pl = headA;
        ListNode ps = headB;
        int lenA = 0;
        int lenB = 0;
        while(pl !=null){
            lenA++;
            pl = pl.next;
        }
        while(ps!=null){
            lenB++;
            ps = ps.next;
        }
        int len = lenA-lenB;
        if(len>=0)
        {
            pl=headA;
            ps=headB;
        }
        if(len<0){
            len = -len;
            pl=headB;
            ps=headA;
        }
        for (int i = 0; i < len; i++) {
            pl=pl.next;
        }
        while(ps!=pl){
            ps=ps.next;
            pl=pl.next;
        }
        return pl;
    }
}
